Below is the class in which I try to push new data to the array of objects
static addCustomer(input) {
// buyTicket
let data = Model.readCustomer();
let theaterId = Number(input[0]);
let name = input[1];
let gender = input[2];
let seatNumber = input[3];
let ticketType = input[4];
let custId = 1;
let theaterName = "xxi";
let movie = "movie";
if (data.length !== 0) {
custId = data[data.length - 1].id + 1;
}
switch (theaterId) {
case 1:
theaterName = "Cinema 12";
movie = "Codezilla";
break;
case 2:
theaterName = "Bioskop IXX";
movie = "The Journey to Center of OOP";
break;
case 3:
theaterName = "Moviemaxx";
movie = "Avatar The Legend of Callback";
break;
case 4:
theaterName = "VGCinema";
movie = "Git The Kungfu Master";
break;
case 5:
theaterName = "Bioskop IXX";
movie = "Json The Protector";
break;
default:
break;
}
let newCustomer = new Customer(
custId,
name,
gender,
new Ticket(theaterName, ticketType, movie, seatNumber)
);
data.push(newCustomer)
console.log(data)
}
This is the console.log result, you notice that the name property of the previous data becomes "undefined" each time I try to push new data to the array.
Below is my "Customer" class in which I import to the models.js file
class Customer {
constructor(id, customerName, gender, ticket) {
this.id = id;
this.customerName = customerName;
this.gender = gender;
this.ticket = new Ticket(
ticket.theaterName,
ticket.type,
ticket.movie,
ticket.seatNumber
);
}
}
class Ticket {
constructor(theaterName, type, movie, seatNumber) {
this.theaterName = theaterName;
this.type = type;
this.movie = movie;
this.seatNumber = seatNumber;
}
}